﻿Imports Training.Common

Partial Public Class AddNewQuizQuestion
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' check for session values
        If IsNothing(Session("qid")) Or IsNothing(Session("qnm")) Then
            ' no sesssion values, check for querystring data
            If IsNothing(Request.QueryString("qid")) Or IsNothing(Request.QueryString("qnm")) Then
                Response.Redirect("QuizControl.aspx")
            Else
                Session("qid") = Request.QueryString("qid")
                Session("qnm") = Request.QueryString("qnm")
                lblQuiz.Text = Session("qnm").ToString
            End If
        Else
            ' we have session values, check for questionid from querystring
            If IsNothing(Request.QueryString("qsid")) Then
                Session("qst") = String.Empty
            Else
                tbQuestion.Text = Request.QueryString("qsid")
                lblQuiz.Text = Session("qnm").ToString
            End If
        End If

    End Sub

    ''' <summary>
    ''' Display link to view question image
    ''' </summary>
    ''' <param name="inm"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ViewImage(ByVal inm) As String
        Dim retVal As String
        retVal = String.Empty

        If inm Is DBNull.Value Then
            retVal = String.Empty
        Else
            retVal = "<a href=""javascript:void(0);"" onclick=""window.open('../images/quizzes/full/" & inm & "','_blank','width=500,height=600,menubar=0,location=0,resizable=0,scrollbars=0');"">view</a>"
        End If

        Return retVal
    End Function

    ''' <summary>
    ''' Continue button click event
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnContinue_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnContinue.Click
        ' create session values for Question and order
        Session("qst") = tbQuestion.Text
        Session("qor") = tbOrder.Text
        'redirect to answer selection
        Response.Redirect("QuestionAnswerSelect.aspx")
    End Sub
End Class